package com.talking.presenter;
import com.talking.model.Http;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;

import okhttp3.Callback;

public class HistoryPresenter {
    public static void query(String senderAccount,String accepterAccount,String type,Callback callback) {
        Http.get("history/query/?senderAccount="+senderAccount+"&accepterAccount="+accepterAccount+"&type="+type,callback);
    }
    public static void add(String content_type,String type,String senderAccount,String accepterAccount,String content,Callback callback) {
        try {
            JSONObject jo=new JSONObject();
            jo.put("content_type",content_type);
            jo.put("type",type);
            jo.put("senderAccount",senderAccount);
            jo.put("accepterAccount",accepterAccount);
            jo.put("content",content);
            Http.post(jo,"history/add/",callback);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    public static void delete(String id,Callback callback) {
        Http.get("history/delete/?id="+id,callback);
    }
    public static void deleteAll(String senderAccount,String accepterAccount,Callback callback) {
        Http.get("history/deleteAll/?senderAccount="+senderAccount+"&accepterAccount="+accepterAccount,callback);
    }
    public static void upload(File file,Callback callback){
        Http.upload("history/upload/",file,callback);
    }

    public static void sendGroupInvitation(String account, JSONArray ja,String groupId,Callback callback) {
        try {
            JSONObject jo=new JSONObject();
            jo.put("friendAccountList",ja);
            jo.put("account",account);
            jo.put("groupId",groupId);
            Http.post(jo,"history/sendGroupInvitation/",callback);
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }
}